 package client;

 import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Random;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
















 public class LoginCryptoLegacy
 {
/*  27 */   private static final Random rand = new Random();
/*  28 */   private static final char[] iota64 = new char[64];



/*  32 */   private static final Logger log = LogManager.getLogger(LoginCryptoLegacy.class);

   static {
/*  35 */     int i = 0;
/*  36 */     iota64[i++] = '.';
/*  37 */     iota64[i++] = '/'; char c;
/*  38 */     for (c = 'A'; c <= 'Z'; c = (char)(c + 1)) {
/*  39 */       iota64[i++] = c;
     }
/*  41 */     for (c = 'a'; c <= 'z'; c = (char)(c + 1)) {
/*  42 */       iota64[i++] = c;
     }
/*  44 */     for (c = '0'; c <= '9'; c = (char)(c + 1)) {
/*  45 */       iota64[i++] = c;
     }
   }







   public static String hashPassword(String password) {
/*  56 */     byte[] randomBytes = new byte[6];
/*  57 */     rand.setSeed(System.currentTimeMillis());
/*  58 */     rand.nextBytes(randomBytes);
/*  59 */     return myCrypt(password, genSalt(randomBytes));
   }









   public static boolean checkPassword(String password, String hash) {
/*  71 */     return myCrypt(password, hash).equals(hash);
   }

   public static boolean isLegacyPassword(String hash) {
/*  75 */     return hash.substring(0, 3).equals("$H$");
   }










   private static String myCrypt(String password, String seed) throws RuntimeException {
/*  88 */     String out = null;
/*  89 */     int count = 8;



/*  93 */     if (!seed.substring(0, 3).equals("$H$")) {

/*  95 */       byte[] randomBytes = new byte[6];
/*  96 */       rand.nextBytes(randomBytes);
/*  97 */       seed = genSalt(randomBytes);
     }

/* 100 */     String salt = seed.substring(4, 12);
/* 101 */     if (salt.length() != 8) {
/* 102 */       throw new RuntimeException("Error hashing password - Invalid seed.");
     }

/* 105 */     try { MessageDigest digester = MessageDigest.getInstance("SHA-1");

/* 107 */       digester.update((salt + password).getBytes("iso-8859-1"), 0, (salt + password).length());
/* 108 */       byte[] sha1Hash = digester.digest();
       while (true)
/* 110 */       { byte[] CombinedBytes = new byte[sha1Hash.length + password.length()];
/* 111 */         System.arraycopy(sha1Hash, 0, CombinedBytes, 0, sha1Hash.length);
/* 112 */         System.arraycopy(password.getBytes("iso-8859-1"), 0, CombinedBytes, sha1Hash.length, (password.getBytes("iso-8859-1")).length);
/* 113 */         digester.update(CombinedBytes, 0, CombinedBytes.length);
/* 114 */         sha1Hash = digester.digest();
/* 115 */         if (--count <= 0) {
/* 116 */           out = seed.substring(0, 12);
/* 117 */           out = out + encode64(sha1Hash);
         } else {
           continue;
         }
/* 121 */         if (out == null) {
/* 122 */           throw new RuntimeException("Error hashing password - out = null");
         }
/* 124 */         return out; }  } catch (NoSuchAlgorithmException|UnsupportedEncodingException Ex) { log.error("Error hashing password." + Ex); }  if (out == null) throw new RuntimeException("Error hashing password - out = null");  return out;
   }









   private static String genSalt(byte[] arrayOfByte) {
/* 136 */     String Salt = "$H$" + iota64[30] + encode64(arrayOfByte);
/* 137 */     return Salt;
   }

   private static String convertToHex(byte[] data) {
/* 141 */     StringBuilder buf = new StringBuilder(); byte[] arrayOfByte; int i; byte b;
/* 142 */     for (arrayOfByte = data, i = arrayOfByte.length, b = 0; b < i; ) { byte aData = arrayOfByte[b];
/* 143 */       int halfbyte = aData >>> 4 & 0xF;
/* 144 */       int two_halfs = 0;
       while (true)
/* 146 */       { if (0 <= halfbyte && halfbyte <= 9) {
/* 147 */           buf.append((char)(48 + halfbyte));
         } else {
/* 149 */           buf.append((char)(97 + halfbyte - 10));
         }
/* 151 */         halfbyte = aData & 0xF;
/* 152 */         if (two_halfs++ >= 1)
           b++;  }  }
/* 154 */      return buf.toString();
   }

   public static String encodeSHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
/* 158 */     MessageDigest md = MessageDigest.getInstance("SHA-1");
/* 159 */     md.update(text.getBytes("iso-8859-1"), 0, text.length());
/* 160 */     return convertToHex(md.digest());
   }







   private static String encode64(byte[] Input) {
/* 170 */     int iLen = Input.length;
/* 171 */     int oDataLen = (iLen * 4 + 2) / 3;
/* 172 */     int oLen = (iLen + 2) / 3 * 4;

/* 174 */     char[] out = new char[oLen];
/* 175 */     int ip = 0;
/* 176 */     int op = 0;
/* 177 */     while (ip < iLen) {
/* 178 */       int i0 = Input[ip++] & 0xFF;
/* 179 */       int i1 = (ip < iLen) ? (Input[ip++] & 0xFF) : 0;
/* 180 */       int i2 = (ip < iLen) ? (Input[ip++] & 0xFF) : 0;
/* 181 */       int o0 = i0 >>> 2;
/* 182 */       int o1 = (i0 & 0x3) << 4 | i1 >>> 4;
/* 183 */       int o2 = (i1 & 0xF) << 2 | i2 >>> 6;
/* 184 */       int o3 = i2 & 0x3F;
/* 185 */       out[op++] = iota64[o0];
/* 186 */       out[op++] = iota64[o1];
/* 187 */       out[op] = (op < oDataLen) ? iota64[o2] : '=';
/* 188 */       op++;
/* 189 */       out[op] = (op < oDataLen) ? iota64[o3] : '=';
/* 190 */       op++;
     }
/* 192 */     return new String(out);
   }
 }


/* Location:              C:\PGX\Server.jar!\client\LoginCryptoLegacy.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */